package com.example.demo.controller;

import com.example.demo.entity.Product;
import com.example.demo.service.ProductService;
import com.example.demo.common.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "产品管理")
@Log4j2
@RequestMapping("product")
@RestController
public class ProductController {
    @Autowired
    private ProductService productService;

    @GetMapping("list1")
    public R list1(
            @RequestParam(defaultValue = "1") int current,
            @RequestParam(defaultValue = "10") int size
    ){
        return R.ok(productService.page1(current, size));
    }
    @ApiOperation(value = "查询列表")
    @GetMapping("list")
    public R list(
            @RequestParam(defaultValue = "1") int current,
            @RequestParam(defaultValue = "10") int size
    ){
        return R.ok(productService.list(current, size));
    }
    @ApiOperation(value = "查询")
    @GetMapping("detail")
    public R detail(long id){
        return R.ok(productService.getById(id));
    }

    @PostMapping("save")
    public R save(Product product){
        return R.okFail(productService.saveOrUpdate(product));
    }
    @GetMapping("remove")
    public R remove(long id){
        return R.okFail(productService.removeById(id));
    }
}
